cmd/goyacc: don't panic on grammar files ending without a newline - #671
cmd/goyacc: don't panic on grammar files ending without a newline#671shaggyinsomniac wants to merge 1 commit into
Conversation
getrune keeps EOF sticky in peekrune (it returns EOF without clearing
the slot), so when gettok's IDENTIFIER/IDENTCOLON look-ahead reaches
end-of-file and ungets the EOF rune, ungetrune hit its single-slot
"2nd unget" panic. A 10-byte grammar such as
%%
S: A; B
(with no trailing newline) crashed with
panic: ungetc - 2nd unget
Make ungetting EOF a no-op: an exhausted reader returns EOF again on
the next read regardless, so behavior for well-formed files is
unchanged. The example above now reports the proper syntax error
("illegal rule: missing semicolon or |"), and a valid grammar
compiles to identical output.
|
This PR (HEAD: 642be10) has been imported to Gerrit for code review. Please visit Gerrit at https://go-review.googlesource.com/c/tools/+/823504. Important tips:
|
|
Message from Gopher Robot: Patch Set 1: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/823504. |
|
Message from Madeline Kalil: Patch Set 1: Commit-Queue+1 Please don’t reply on this GitHub thread. Visit golang.org/cl/823504. |
|
Message from golang-scoped@luci-project-accounts.iam.gserviceaccount.com: Patch Set 1: Dry run: CV is trying the patch. Bot data: {"action":"start","triggered_at":"2026-09-01T17:06:23Z","revision":"ae26d2c4381592fcbc8cc1df7c89b1049ea1857e"} Please don’t reply on this GitHub thread. Visit golang.org/cl/823504. |
|
Message from Madeline Kalil: Patch Set 1: -Commit-Queue (Performed by <GERRIT_ACCOUNT_60063> on behalf of <GERRIT_ACCOUNT_3771561>) Please don’t reply on this GitHub thread. Visit golang.org/cl/823504. |
|
Message from golang-scoped@luci-project-accounts.iam.gserviceaccount.com: Patch Set 1: This CL has passed the run Please don’t reply on this GitHub thread. Visit golang.org/cl/823504. |
|
Message from golang-scoped@luci-project-accounts.iam.gserviceaccount.com: Patch Set 1: LUCI-TryBot-Result+1 Please don’t reply on this GitHub thread. Visit golang.org/cl/823504. |
Fixes golang/go#81182.
getrunekeeps EOF sticky in the single-slotpeekrunebuffer (it returns EOF without clearing the slot). Whengettok's IDENTIFIER/IDENTCOLON look-ahead reaches end-of-file and ungets the EOF rune,ungetrunehits its single-slot "2nd unget" panic — a 10-byte grammar with no trailing newline crashes:Make ungetting EOF a no-op: an exhausted reader returns EOF again on the next read regardless, so behavior for well-formed files is unchanged. With the fix the example reports the proper
illegal rule: missing semicolon or |error and exits 1, and a valid grammar compiles to identical output.